<template>
    <van-row>
        <van-col :span="24">

            <van-address-edit
                :area-list="areaList"
                show-delete
                show-set-default
                show-search-result
                :search-result="searchResult"
                :area-columns-placeholder="['请选择', '请选择', '请选择']"
                @save="onSave"
                @delete="onDelete"
                @change-detail="onChangeDetail"
                />

        </van-col>
    </van-row>
</template>

<script setup>
import { ref,onMounted, getCurrentInstance } from "vue";
import { areaList } from '@vant/area-data';
import {showNotify} from 'vant';

const {proxy} = getCurrentInstance();

const searchResult = ref([]);

const onSave = (addressEditInfo) => {
    console.log('save---',addressEditInfo);
    let address = {
        contactName: addressEditInfo.name,
        contactTel: addressEditInfo.tel,
        address: addressEditInfo.province+addressEditInfo.city+addressEditInfo.county+addressEditInfo.addressDetail,
        userId: userId.value
    }

    proxy.$axios({
        method: 'post',
        url: '/address/save',
        data: address
    }).then(res=>{
        let resultBean = res.data;
        if(resultBean.code == 200){
            
        }else{
            showNotify({message: resultBean.msg});
        }
    }).catch(error=>{
        showNotify({message: error.message});
    })

};
const onDelete = () => showToast('delete');

   const userId = ref(null);

   onMounted(()=>{

        userId.value = 1;


   })
</script>

<style>
</style>